package com.com.typhoon.producer;

import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.CommandLineRunner;
import org.springframework.jms.core.JmsMessagingTemplate;
import org.springframework.stereotype.Component;

import javax.jms.Queue;
import javax.jms.Topic;

/**
 * @author shuya | dongfeng.zdf@alibaba-inc.com
 * @description
 * @date 2018/10/29 上午10:42
 * @description
 * @modified by
 * @since V2.0.0
 */
@Component
@Slf4j
public class Producer implements CommandLineRunner {

    @Autowired
    private JmsMessagingTemplate jmsMessagingTemplate;

    @Autowired
    private Queue queue;

    @Autowired
    private Topic topic;

    /**
     * Callback used to run the bean.
     *
     * @param args incoming main method arguments
     * @throws Exception on error
     */
    @Override
    public void run(String... args) throws Exception {
        this.sendQueue("this is a sample message");
        log.info("message was send to the queue");
        this.sendTopic("this is a sample topic message");
        log.info("message was send to the topic");
    }
    public void sendQueue(String msg) {
        this.jmsMessagingTemplate.convertAndSend(this.queue, msg);
    }

    public void sendTopic(String msg) {
        this.jmsMessagingTemplate.convertAndSend(this.topic,msg);
    }
}
